import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_widgets_pc/resources/kq_theme_colors.dart';
import 'package:flutter_widgets_pc/utils/native/file_picker_native_util.dart';
import 'package:flutter_widgets_pc/widgets/formItem/entity/kq_form_entity.dart';
import 'package:flutter_widgets_pc/widgets/formItem/kq_attachment_view.dart';
import 'package:flutter_widgets_pc/widgets/image/kq_image.dart';
import 'package:flutter_widgets_pc/widgets/imageBox/kq_head_image_view.dart';
import 'package:flutter_widgets_pc/widgets/imageBox/kq_image_box.dart';
import 'package:flutter_widgets_pc/widgets/titleBar/kq_title_bar.dart';
import 'package:flutter_widgets_pc/widgets/wrapFlow/kq_auto_column_flow.dart';
import 'package:flutter_widgets_pc_example/resources/Images.dart';
import 'package:flutter_widgets_pc/widgets/dialog/kq_upload.dart';

/// 自定义控件演示页面
class CustomExpandView extends StatefulWidget {
  const CustomExpandView({super.key});

  @override
  State<StatefulWidget> createState() {
    return CustomExpandViewState();
  }
}

class CustomExpandViewState extends State<CustomExpandView> {
  ImageUrl? imgUrl = ImageUrl(
      imageType: ImageType.http,
      url: 'https://imgs.699pic.com/01/500/628/783/500628783.jpg!list2x.v1');
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: KqHeadBar(
          headTitle: "自定义控件演示2",
          back: () => Get.back(),
        ),
        body: SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
          child: Column(
            children: [
              KqHeadImageView(
                editable: true,
                defaultUrl: ImageUrl(
                    imageType: ImageType.assets, url: Images.remakeIcAddRemake),
                isCircle: true,
                isOriginal: false,
                gradient: const LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomLeft,
                    stops: [0.0, 1.0],
                    colors: [KqThemeColors.textBlue, KqThemeColors.bgWhite]),
                didDelete: () {
                  setState(() {
                    imgUrl = null;
                  });
                },
                didSelected: () {
                  //上传图片
                  KqUpload().handleUpload(context, ((files) {
                    setState(() {
                      KqFile xfile = files.first;
                      imgUrl = ImageUrl(
                          imageType: ImageType.file, url: xfile.filePath!);
                    });
                  }));
                },
                netUrl: imgUrl,
              ),
              SizedBox(height: 10),
              KqHeadImageView(
                defaultUrl: ImageUrl(
                    imageType: ImageType.assets, url: Images.remakeIcAddRemake),
                isCircle: true,
                isOriginal: true,
                gradient: const LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomLeft,
                    stops: [0.0, 1.0],
                    colors: [KqThemeColors.textBlue, KqThemeColors.bgWhite]),
                didDelete: () {
                  setState(() {
                    imgUrl = null;
                  });
                },
                didSelected: () {
                  //上传图片
                  KqUpload().handleUpload(context, ((files) {
                    setState(() {
                      KqFile xfile = files.first;
                      imgUrl = ImageUrl(
                          imageType: ImageType.file, url: xfile.filePath!);
                    });
                  }));
                },
                netUrl: imgUrl,
              ),
              SizedBox(height: 10),
              KqAttachmentView(
                entity: KqFormEntity(title: '附件信息', extraData: [
                  {'attachmentName': 'xssssss.docx', 'xx': 'xx'},
                  {
                    'attachmentName':
                        'jdhbesdfrefeferefefefefefewfwewefwefwefwefewf.xls'
                  }
                ]),
              ),
              SizedBox(height: 10),
              Container(
                color: Colors.white,
                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
                child: KqAutoColumnFlow(
                  backgroundColor: KqThemeColors.bgD,
                  rowCountCallback: () {
                    return 5;
                  },
                  totalCountCallback: (() {
                    return 9;
                  }),
                  renderCrossAxisCountCallback: ((row) {
                    if (row == 0) {
                      return 1;
                    } else if (row == 1) {
                      return 3;
                    }
                    return 2;
                  }),
                  renderIconPathCallback: (row, column) {
                    if (column == 0) {
                      return Images.homeIcBanbenhao;
                    }
                    return Images.demoIcChoice16Sel;
                  },
                  renderTextCallback: ((row, column) {
                    if (column == 0) {
                      return '第${row}行只有${column}个';
                    }
                    return '2023-09-09 13:59';
                  }),
                  renderTextMaxLineCallback: (row, column) {
                    return 1;
                  },
                ),
              ),
            ],
          ),
        ));
  }
}
